package com.supms.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.supms.course.domain.AttendItems;
import com.supms.course.service.IAttendItemsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 听课评价项Controller
 *
 * @author LiangHao
 * @date 2022-02-27
 */
@RestController
@RequestMapping("/attendItems")
public class AttendItemsController extends BaseController {
    @Autowired
    private IAttendItemsService attendItemsService;

    /**
     * 查询听课评价项列表
     */
    @RequiresPermissions("course:attendItems:list")
    @GetMapping("/list")
    public TableDataInfo list(AttendItems attendItems) {
        startPage();
        List<AttendItems> list = attendItemsService.selectAttendItemsList(attendItems);
        return getDataTable(list);
    }

    /**
     * 导出听课评价项列表
     */
    @RequiresPermissions("course:attendItems:export")
    @Log(title = "听课评价项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendItems attendItems) {
        List<AttendItems> list = attendItemsService.selectAttendItemsList(attendItems);
        ExcelUtil<AttendItems> util = new ExcelUtil<AttendItems>(AttendItems.class);
        util.exportExcel(response, list, "听课评价项数据");
    }

    /**
     * 获取听课评价项详细信息
     */
    @RequiresPermissions("course:attendItems:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(attendItemsService.selectAttendItemsById(id));
    }

    /**
     * 新增听课评价项
     */
    @RequiresPermissions("course:attendItems:add")
    @Log(title = "听课评价项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendItems attendItems) {
        return toAjax(attendItemsService.insertAttendItems(attendItems));
    }

    /**
     * 修改听课评价项
     */
    @RequiresPermissions("course:attendItems:edit")
    @Log(title = "听课评价项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendItems attendItems) {
        return toAjax(attendItemsService.updateAttendItems(attendItems));
    }

    /**
     * 删除听课评价项
     */
    @RequiresPermissions("course:attendItems:remove")
    @Log(title = "听课评价项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(attendItemsService.deleteAttendItemsByIds(ids));
    }

    /**
     * 获取当前课类型的听课评价项表
     */
    @GetMapping("/item/{typeNum}")
    public List<AttendItems> getAttendItem(@PathVariable String typeNum) {
        return attendItemsService.selectAttendItemByType(typeNum);
    }

    /**
     * 添加听课评价
     */
    @PostMapping("/addAttendEval")
    public AjaxResult addAttendEval(@RequestBody List<AttendItems> attendItemsList) {
        return toAjax(attendItemsService.addAttenEval(attendItemsList));
    }

    /**
     * 通过听课表ID查看听课评价
     */
    @GetMapping("/getAttendEval/{attendId}")
    public List<AttendItems> getAttendEval(@PathVariable Long attendId) {
        return attendItemsService.getAttendEvalByAttendId(attendId);
    }
}
